package com.chunuo.statistics.controller;


import com.chunuo.commonutils.R;
import com.chunuo.statistics.service.DailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-31
 */
@RestController
@RequestMapping("/statistics/daily")
public class DailyController {

    @Autowired
    private DailyService dailyService;

    //统计某一天注册人数,生成统计数据
    @PostMapping("registerCount/{day}")
    public R registerCount(@PathVariable String day) {
        dailyService.registerCount(day);
        return R.ok();
    }

    /**
     * 获取Echarts需要的两组数据  x轴的日期和数量
     * 显示指定天数区间的数据
     * @param type
     * @param before
     * @param after
     * @return
     */
    @GetMapping("getEcharts/{type}/{before}/{after}")
    public R getEcharts(@PathVariable("type")String type,
                        @PathVariable("before")String before,
                        @PathVariable("after")String after){
        Map<String,Object> map = dailyService.getEcharts(type,before,after);
        return R.ok().data(map);
    }

}

